<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>02_selenium_ide</title>
<link rel="stylesheet" type="text/css" href="css/mystyle.css"/>
</head>
<body>

<div class="body">

  <div class="section" id="selenium-ide">
<h1>Selenium-IDE
<a class="headerlink" href="#selenium-ide" title="Permalink to this headline">¶</a>
<span class="subTitle"><a href="http://www.seleniumhq.org/docs/02_selenium_ide.jsp">online</a></span>
</h1>
<div class="section" id="introduction">
<span id="chapter02-reference"></span><h2>Introduction<a class="headerlink" href="#introduction" title="Permalink to this headline">¶</a></h2>
<p>The Selenium-IDE (Integrated Development Environment) is the tool you use to
develop your Selenium test cases.  It’s an easy-to-use Firefox plug-in and is
generally the most efficient way to develop test cases.  It also contains a
context menu that allows you to first select a UI element from the browser’s
currently displayed page and then select from a list of Selenium commands
with parameters pre-defined according to the context of the selected UI
element.  This is not only a time-saver, but also an excellent way of
learning Selenium script syntax.</p>
<p>Selenium-IDE（集成开发环境）是您用来开发您的Selenium测试用例的工具。 这是一个易于使用的Firefox插件，通常是开发测试用例最有效的方法。 它还包含一个上下文菜单，允许您首先从浏览器当前显示的页面中选择一个UI元素，然后从Selenium命令列表中进行选择，并根据所选UI元素的上下文预定义参数。 这不仅是一个节省时间，而且是一个学习Selenium脚本语法的好方法。</p>
<p>This chapter is all about the Selenium IDE and how to use it effectively.</p>
<p>本章全面介绍Selenium IDE以及如何有效地使用它。</p>
</div>
<div class="section" id="installing-the-ide">
<h2>Installing the IDE<a class="headerlink" href="#installing-the-ide" title="Permalink to this headline">¶</a></h2>
<p>Using Firefox, first, download the IDE from the SeleniumHQ <a class="reference external" href="http://seleniumhq.org/download/">downloads page</a></p>
<p>Firefox will protect you from installing addons from unfamiliar locations, so
you will need to click ‘Allow’ to proceed with the installation, as shown in the
following screenshot.</p>
<p>Firefox将保护您免于从不熟悉的位置安装插件，因此您需要点击“允许”才能继续安装，如下图所示。</p>
<img alt="_images/chapt3_img01_IDE_Installation.png" class="align-center" src="_images/chapt3_img01_IDE_Installation.png">
<p>When downloading from Firefox, you’ll be presented with the following window. <span class="subA">从Firefox下载时，会出现以下窗口。</span></p>
<img alt="_images/chapt3_img02_IDE_Installation.png" class="align-center" src="_images/chapt3_img02_IDE_Installation.png">
<p>Select Install Now. The Firefox Add-ons window pops up, first showing a
progress bar, and when the download is complete, displays the following. <span class="subA">选择立即安装。 弹出Firefox附加组件窗口，首先显示一个进度条，当下载完成时，显示以下内容。</span></p>
<img alt="_images/chapt3_img03_IDE_Installation.png" class="align-center" src="_images/chapt3_img03_IDE_Installation.png">
<p>Restart Firefox.  After Firefox reboots you will find the Selenium-IDE listed under the Firefox Tools menu. <span class="subA">重新启动Firefox。  Firefox重新启动后，您会在Firefox Tools菜单下找到列出的Selenium-IDE。</span> </p>
<img alt="_images/chapt3_img04_IDE_Installation.png" class="align-center" src="_images/chapt3_img04_IDE_Installation.png">
</div>
<div class="section" id="opening-the-ide">
<h2>Opening the IDE<a class="headerlink" href="#opening-the-ide" title="Permalink to this headline">¶</a></h2>
<p>To run the Selenium-IDE, simply select it from the Firefox Tools menu.  It opens
as follows with an empty script-editing window and a menu for loading, or
creating new test cases. <span class="subA">要运行Selenium-IDE，只需从Firefox Tools菜单中选择它。 它打开如下，一个空的脚本编辑窗口和一个菜单用于加载，或创建新的测试用例。</span> </p>
<img alt="_images/chapt3_img05_IDE_open.png" class="align-center" src="_images/chapt3_img05_IDE_open.png">
</div>
<div class="section" id="ide-features">
<h2>IDE Features<a class="headerlink" href="#ide-features" title="Permalink to this headline">¶</a></h2>
<div class="section" id="menu-bar">
<h3>Menu Bar<a class="headerlink" href="#menu-bar" title="Permalink to this headline">¶</a></h3>
<p>The File menu has options for Test Case and Test Suite (suite of Test Cases).
Using these you can add a new Test Case, open a Test Case, save a Test Case,
export Test Case in a language of your choice. You can also open the recent
Test Case. All these options are also available for Test Suite.</p>
<p>文件菜单有测试用例和测试套件（测试用例套件）的选项。 使用这些，您可以添加一个新的测试用例，打开测试用例，保存测试用例，用您选择的语言导出测试用例。 您也可以打开最近的测试用例。 所有这些选项也可用于测试套件。</p>

<p>The Edit menu allows copy, paste, delete, undo, and select all
operations for editing the commands in your test case.  The Options menu allows
the changing of settings.  You can set the timeout value for
certain commands, add user-defined user extensions to the base set of Selenium
commands, and specify the format (language) used when saving your
test cases.  The Help menu is the standard Firefox Help menu; only one
item on this menu–UI-Element Documentation–pertains to Selenium-IDE.</p>
<p>编辑菜单允许复制，粘贴，删除，撤消和选择所有操作来编辑测试用例中的命令。 选项菜单允许更改设置。 您可以设置某些命令的超时值，将用户定义的用户扩展添加到基本的Selenium命令集中，并指定保存测试用例时使用的格式（语言）。 帮助菜单是标准的Firefox帮助菜单; 在这个菜单中只有一个项目 -  UI元素文档 - 属于Selenium-IDE。</p>

</div>
<div class="section" id="toolbar">
<h3>Toolbar<a class="headerlink" href="#toolbar" title="Permalink to this headline">¶</a></h3>
<p>The toolbar contains buttons for controlling the execution of your test
cases, including a step feature for debugging your test cases.  The right-most
button, the one with the red-dot, is the record button.</p>
<p>工具栏包含用于控制测试用例执行的按钮，包括调试测试用例的步骤功能。 记录按钮，最右边的按钮，红色的按钮。</p>


<img alt="_images/chapt3_img06_IDE_features.png" class="align-center" src="_images/chapt3_img06_IDE_features.png">
<dl class="docutils">
<dt><img alt="speed control" src="_images/chapt3_img07_Speed_Control.png"></dt>
<dd>Speed Control:  controls how fast your test case runs. <span class="subA">控制测试用例的运行速度。</span> </dd>
<dt><img alt="run all" src="_images/chapt3_img08_Run_All.png"></dt>
<dd>Run All: Runs the entire test suite when a test suite with multiple test
cases is loaded. <span class="subA">装载多个测试用例的测试套件时运行整个测试套件。</span> </dd>
<dt><img alt="run" src="_images/chapt3_img09_Run.png"></dt>
<dd>Run:  Runs the currently selected test.  When only a single test is
loaded this button and the Run All button have the same effect. <span class="subA">运行当前选择的测试。 当只有一个测试被加载时，这个按钮和全部运行按钮具有相同的效果。</span></dd>
<dt><img alt="pause" src="_images/chapt3_img10_Pause.png"> <img alt="resume" src="_images/chapt3_img11_Resume.png"></dt>
<dd>Pause/Resume:  Allows stopping and re-starting of a running test case. <span class="subA">允许停止和重新启动正在运行的测试用例。</span> </dd>
<dt><img alt="step" src="_images/chapt3_img12_Step.png"></dt>
<dd>Step:  Allows you to “step” through a test case by running it one command at a
time.  Use for debugging test cases. <span class="subA">允许您通过一次运行一个命令来“测试”一个测试用例。 用于调试测试用例。</span> </dd>
<dt><img alt="testrunner" src="_images/chapt3_img13_TestRunner_Mode.png"></dt>
<dd>TestRunner Mode:  Allows you to run the test case in a browser loaded with
the Selenium-Core TestRunner.  The TestRunner is not commonly used now
and is likely to be deprecated.  This button is for evaluating test cases
for backwards compatibility with the TestRunner.  Most users will
probably not need this button. <span class="subA">允许您在装载了Selenium-Core TestRunner的浏览器中运行测试用例。  TestRunner现在不常用，可能会被弃用。 此按钮用于评估与TestRunner向后兼容的测试用例。 大多数用户可能不需要这个按钮。</span> </dd>
<dt><img alt="rollup" src="_images/chapt3_img14_Apply_Rollup_Rules.png"></dt>
<dd>Apply Rollup Rules: This advanced feature allows repetitive sequences of
Selenium commands to be grouped into a single action.  Detailed documentation
on rollup rules can be found in the UI-Element Documentation on the Help
menu. <span class="subA">这个高级特性允许将重复的Selenium命令序列分组为一个单独的动作。 汇总规则的详细文档可以在帮助菜单的UI元素文档中找到。</span> </dd>
<dt><img alt="record" src="_images/chapt3_img15_Record.png"></dt>
<dd>Record:  Records the user’s browser actions. <span class="subA">记录用户的浏览器操作。</span> </dd>
</dl>
</div>
<div class="section" id="test-case-pane">
<h3>Test Case Pane<a class="headerlink" href="#test-case-pane" title="Permalink to this headline">¶</a></h3>
<p>Your script is displayed in the test case pane.  It has two tabs, one for
displaying the command and their parameters in a readable “table” format.</p>
<p>您的脚本显示在测试案例窗格中。 它有两个选项卡，一个用于以可读“表格”格式显示命令及其参数。</p>

<img alt="_images/chapt3_img16_Table_Format.png" class="align-center" src="_images/chapt3_img16_Table_Format.png">
<p>The other tab - Source displays the test case in the native format in which the file
will be stored.  By default, this is HTML although it can be changed to a
programming language such as Java or C#, or a scripting language like Python.
See the Options menu for details.  The Source view also allows one to edit
the test case in its raw form, including copy, cut and paste operations.</p>
<p>另一个选项卡 -  Source以用来存储文件的本地格式显示测试用例。 默认情况下，这是HTML，但可以更改为Java或C＃等编程语言或Python等脚本语言。 有关详情，请参阅选项菜单。  Source视图还允许用户以原始形式编辑测试用例，包括复制，剪切和粘贴操作。</p>

<p>The Command, Target, and Value entry fields display the currently selected
command along with its parameters.  These are entry fields where you
can modify the currently selected command.  The first parameter specified for
a command in the Reference tab of the bottom pane always goes in the Target
field.  If a second parameter is specified by the Reference tab, it always
goes in the Value field.</p>
<p>命令，目标和值输入字段显示当前选定的命令及其参数。 这些是可以修改当前所选命令的输入字段。 在底部窗格的“引用”选项卡中为命令指定的第一个参数始终位于“目标”字段中。 如果“引用”选项卡指定了第二个参数，则它始终位于“值”字段中。</p>

<img alt="_images/chapt3_img17_Entry_Fields.png" class="align-center" src="_images/chapt3_img17_Entry_Fields.png">
<p>If you start typing in the Command field, a drop-down list will be populated
based on the first characters you type; you can then select your desired
command from the drop-down.</p>
<p>如果您开始在“命令”字段中输入内容，则会根据您输入的第一个字符填充下拉列表; 你可以从下拉菜单中选择你想要的命令。</p>

</div>
<div class="section" id="log-reference-ui-element-rollup-pane">
<h3>Log/Reference/UI-Element/Rollup Pane<a class="headerlink" href="#log-reference-ui-element-rollup-pane" title="Permalink to this headline">¶</a></h3>
<p>The bottom pane is used for four different functions–Log, Reference,
UI-Element, and Rollup–depending on which tab is selected.</p>
<p>底部窗格用于四个不同的功能 - 日志，引用，UI元素和汇总 - 取决于选择哪个选项卡。</p>

<div class="section" id="log">
<h4>Log<a class="headerlink" href="#log" title="Permalink to this headline">¶</a></h4>
<p>When you run your test case, error messages
and information messages showing the progress are displayed
in this pane automatically, even if you do not first select the Log
tab.  These messages are often useful for test case debugging.   Notice the Clear
button for clearing the Log.  Also notice the Info button is a drop-down
allowing selection of different levels of information to log.</p>
<p>运行测试用例时，即使不首先选择“日志”选项卡，也会自动在此窗格中显示显示进度的错误消息和信息消息。 这些消息通常用于测试用例调试。 注意清除日志清除按钮。 另外请注意，“信息”按钮是一个下拉菜单，允许选择不同级别的信息进行登录。</p>


<img alt="_images/chapt3_img18_Bottom_Box.png" class="align-center" src="_images/chapt3_img18_Bottom_Box.png">
</div>
<div class="section" id="reference">
<h4>Reference<a class="headerlink" href="#reference" title="Permalink to this headline">¶</a></h4>
<p>The Reference tab is the default selection whenever you are
entering or modifying <a class="reference internal" href="#selenese">Selenese</a> commands and parameters in Table
mode.  In Table mode, the Reference pane will display documentation on the current command.  When entering or modifying
commands, whether from Table or Source mode, it is critically
important to ensure that the parameters specified in the
Target and Value fields match those specified in the parameter
list in the Reference pane.  The number of parameters provided
must match the number specified, the order of parameters provided must
match the order specified, and the type of parameters provided must match
the type specified.
If there is a mismatch in any of these three areas, the command will not
run correctly.</p>
<p>无论何时在表格模式下输入或修改Selenese命令和参数，“参考”选项卡都是默认选择。 在“表格”模式下，“参考”窗格将显示当前命令的文档。 在输入或修改命令时，无论是来自表模式还是源模式，确保“目标”和“值”字段中指定的参数都与“参考”窗格中参数列表中指定的参数匹配非常重要。 提供的参数数量必须与指定的数量相匹配，提供的参数顺序必须与指定的顺序相匹配，并且提供的参数类型必须与指定的类型相匹配。 如果这三个区域中的任何一个不匹配，命令将无法正确运行。</p>


<img alt="_images/chapt3_img19_Bottom_Box_Ref.png" class="align-center" src="_images/chapt3_img19_Bottom_Box_Ref.png">
<p>While the Reference tab is invaluable as a quick reference, it is still often
necessary to consult the Selenium <a class="reference external" href="http://release.openqa.org/selenium-core/1.0/reference.html">Reference</a> document.</p>
<p>虽然“引用”选项卡作为快速参考非常有用，但仍经常需要查阅“Selenium参考”文档。</p>
</div>
<div class="section" id="ui-element-and-rollup">
<h4>UI-Element and Rollup<a class="headerlink" href="#ui-element-and-rollup" title="Permalink to this headline">¶</a></h4>
<p>Detailed information on these two panes (which cover advanced features)
can be found in the
UI-Element Documentation on the Help menu of Selenium-IDE.</p>
<p>有关这两个窗格的详细信息（包含高级功能）可以在Selenium-IDE的帮助菜单的UI元素文档中找到。</p>

</div>
</div>
</div>
<div class="section" id="building-test-cases">
<h2>Building Test Cases<a class="headerlink" href="#building-test-cases" title="Permalink to this headline">¶</a></h2>
<p>There are three primary methods for developing test cases.  Frequently,
a test
developer will require all three techniques.</p>
<p>开发测试用例主要有三种方法。 测试开发者通常需要所有三种技术。</p>


<div class="section" id="recording">
<h3>Recording<a class="headerlink" href="#recording" title="Permalink to this headline">¶</a></h3>
<p>Many first-time users begin by recording a test case from their interactions
with a website.  When Selenium-IDE is first opened, the record button is ON by
default. If you do not want Selenium-IDE to begin recording automatically you
can turn this off by going under Options &gt; Options… and deselecting
“Start recording immediately on open.”</p>
<p>许多初次使用者从与网站互动记录测试案例开始。 当第一次打开Selenium-IDE时，默认情况下记录按钮是打开的。 如果您不希望Selenium-IDE自动开始录制，您可以通过在选项>选项...下取消选择“在打开时立即开始录制”。</p>




<p>During recording, Selenium-IDE will automatically insert commands into your
test case based on
your actions.  Typically, this will include:</p>
<ul class="simple">
<li>clicking a link - <em>click</em> or <em>clickAndWait</em> commands</li>
<li>entering values - <em>type</em> command</li>
<li>selecting options from a drop-down listbox - <em>select</em> command</li>
<li>clicking checkboxes or radio buttons - <em>click</em> command</li>
</ul>
<p>Here are some “gotchas” to be aware of:</p>
<ul class="simple">
<li>The <em>type</em> command may require clicking on some other area of the web page
for it to record.</li>
<li>Following a link usually records a <em>click</em> command. You will often need to
change this to <em>clickAndWait</em> to ensure your test case pauses until the new page
is completely loaded.  Otherwise, your test case will continue running commands
before the page has loaded all its UI elements. This will cause unexpected
test case failures.</li>
</ul>
</div>
<div class="section" id="adding-verifications-and-asserts-with-the-context-menu">
<h3>Adding Verifications and Asserts With the Context Menu<a class="headerlink" href="#adding-verifications-and-asserts-with-the-context-menu" title="Permalink to this headline">¶</a></h3>
<p>Your test cases will also need to check the properties of a web-page.  This
requires <em>assert</em> and <em>verify</em> commands.  We won’t describe the specifics of
these commands here; that is in the chapter on <a class="reference internal" href="#selenium-commands-selenese">Selenium Commands – “Selenese”</a>.  Here we’ll
simply describe how to add them to your test case.</p>
<p>With Selenium-IDE recording, go to the browser displaying your test application and
right click anywhere on the page.  You will see a context menu showing <em>verify</em>
and/or <em>assert</em> commands.</p>
<p>The first time you use Selenium, there may only be one Selenium command listed.
As you use the IDE however, you will find additional commands will quickly be
added to this menu.  Selenium-IDE will attempt to predict what command, along
with the parameters, you will need for a selected UI element on the current
web-page.</p>
<p>Let’s see how this works. Open a web-page of your choosing and select a block
of text on the page. A paragraph or a heading will work fine.  Now, right-click
the selected text.  The context menu should give you a <em>verifyTextPresent</em>
command and the suggested parameter should be the text itself.</p>
<p>Also, notice the Show All Available Commands menu option.  This shows many,
many more commands, again, along with suggested parameters, for testing your
currently selected UI element.</p>
<p>Try a few more UI elements. Try right-clicking an image, or a user control
like a button or a checkbox.  You may need to use Show All Available Commands
to see options other than <em>verifyTextPresent</em>. Once you select these other
options, the more commonly used ones will show up on the primary context menu.
For example, selecting <em>verifyElementPresent</em> for an image should later cause
that command to be available on the primary context menu the next time you
select an image and right-click.</p>
<p>Again, these commands will be explained in detail in the chapter on Selenium
commands.  For now though, feel free to use the IDE to record and select
commands into a test case and then run it.  You can learn a lot about
the Selenium commands simply by experimenting with the IDE.</p>
</div>
<div class="section" id="editing">
<h3>Editing<a class="headerlink" href="#editing" title="Permalink to this headline">¶</a></h3>
<div class="section" id="insert-command">
<h4>Insert Command<a class="headerlink" href="#insert-command" title="Permalink to this headline">¶</a></h4>
<div class="section" id="table-view">
<h5>Table View<a class="headerlink" href="#table-view" title="Permalink to this headline">¶</a></h5>
<p>Select the point in your test case where you want to insert the command.
To do this, in the Test Case Pane, left-click on the line where you want
to insert a new command.  Right-click and select Insert Command; the IDE
will add a blank line just ahead of the line you selected. Now use the
command editing text fields to enter your new command and its parameters.</p>
</div>
<div class="section" id="source-view">
<h5>Source View<a class="headerlink" href="#source-view" title="Permalink to this headline">¶</a></h5>
<p>Select the point in your test case where you want to insert the command.
To do this, in the Test Case Pane, left-click between the commands
where you want to insert a new command, and enter the HTML tags needed
to create a 3-column row containing the Command, first parameter
(if one is required by the Command), and second parameter (again,
if one is required to locate an element) and third parameter(again, if one is required to have a value).
Example:</p>
<div class="highlight-html"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span><span class="p">&gt;</span>Command<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span><span class="p">&gt;</span>target (locator)<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">td</span><span class="p">&gt;</span>Value<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
</pre></div>
</div>
</div>
</div>
<div class="section" id="insert-comment">
<h4>Insert Comment<a class="headerlink" href="#insert-comment" title="Permalink to this headline">¶</a></h4>
<p>Comments may be added to make your test case more readable.  These comments are
ignored when the test case is run.</p>
<p>Comments may also be used to add vertical white space (one or more blank lines)
in your tests; just create empty comments.  An empty command will cause an error
during execution; an empty comment won’t.</p>
<div class="section" id="id2">
<h5>Table View<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h5>
<p>Select the line in your test case where you
want to insert the comment.  Right-click and select Insert Comment.  Now use
the Command field to enter the comment.  Your comment will appear in purple
text.</p>
</div>
<div class="section" id="id3">
<h5>Source View<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h5>
<p>Select the point in your test case where you want to insert the comment.  Add
an HTML-style comment, i.e., <code class="docutils literal"><span class="pre">&lt;!--</span> <span class="pre">your</span> <span class="pre">comment</span> <span class="pre">here</span> <span class="pre">--&gt;</span></code>.</p>
</div>
</div>
<div class="section" id="edit-a-command-or-comment">
<h4>Edit a Command or Comment<a class="headerlink" href="#edit-a-command-or-comment" title="Permalink to this headline">¶</a></h4>
<div class="section" id="id4">
<h5>Table View<a class="headerlink" href="#id4" title="Permalink to this headline">¶</a></h5>
<p>Simply select the line to be changed and edit it using the Command, Target,
and Value fields.</p>
</div>
<div class="section" id="id5">
<h5>Source View<a class="headerlink" href="#id5" title="Permalink to this headline">¶</a></h5>
<p>Since Source view provides the equivalent of a WYSIWYG (What You See is What You Get) editor, simply modify
which line you wish–command, parameter, or comment.</p>
</div>
</div>
</div>
<div class="section" id="opening-and-saving-a-test-case">
<h3>Opening and Saving a Test Case<a class="headerlink" href="#opening-and-saving-a-test-case" title="Permalink to this headline">¶</a></h3>
<p>Like most programs, there are Save and Open commands under the File menu.
However, Selenium distinguishes between test cases and test suites.
To save your Selenium-IDE tests for later use you can either save the
individual test cases, or save the test suite. If the test cases of your
test suite have not been saved, you’ll be prompted to save them before
saving the test suite.</p>
<p>When you open an existing test case or suite, Selenium-IDE
displays its Selenium commands in the Test Case Pane.</p>
</div>
</div>
<div class="section" id="running-test-cases">
<h2>Running Test Cases<a class="headerlink" href="#running-test-cases" title="Permalink to this headline">¶</a></h2>
<p>The IDE allows many options for running your test case. You can run a test case
all at once, stop and start it, run it one line at a time, run a single command
you are currently developing, and you can do a batch run of an entire test suite.
Execution of test cases is very flexible in the IDE.</p>
<dl class="docutils">
<dt>Run a Test Case</dt>
<dd>Click the Run button to run the currently displayed test case.</dd>
<dt>Run a Test Suite</dt>
<dd>Click the Run All button to run all the test cases in the currently loaded
test suite.</dd>
<dt>Stop and Start</dt>
<dd>The Pause button can be used to stop the test case while it is running.  The
icon of this button then changes to indicate the Resume button.  To continue
click Resume.</dd>
<dt>Stop in the Middle</dt>
<dd>You can set a breakpoint in the test case to cause it to stop on a
particular command.  This is useful for debugging your test case. To set a
breakpoint, select a command, right-click, and from the context menu
select Toggle Breakpoint.</dd>
<dt>Start from the Middle</dt>
<dd>You can tell the IDE to begin running from a specific command in the
middle of the test case.  This also is used for debugging.  To set a
startpoint, select a command, right-click, and from the context menu
select Set/Clear Start Point.</dd>
<dt>Run Any Single Command</dt>
<dd>Double-click any single command to run it by itself.  This is useful when
writing a single command.  It lets you immediately test a command you are
constructing, when you are not sure if it is correct.  You can double-click it to
see if it runs correctly.  This is also available from the context menu.</dd>
</dl>
</div>
<div class="section" id="using-base-url-to-run-test-cases-in-different-domains">
<h2>Using Base URL to Run Test Cases in Different Domains<a class="headerlink" href="#using-base-url-to-run-test-cases-in-different-domains" title="Permalink to this headline">¶</a></h2>
<p>The <em>Base URL</em> field at the top of the Selenium-IDE window is very useful
for allowing test cases to be run across different domains.
Suppose that a site named http://news.portal.com had an in-house beta site named
http://beta.news.portal.com.  Any test cases for these sites that begin with
an <em>open</em>
statement should specify a <em>relative URL</em> as the argument to <em>open</em>
rather than an <em>absolute URL</em> (one
starting with a protocol such as http: or https:).  Selenium-IDE will
then create an absolute URL by appending the <em>open</em> command’s
argument onto the end of the value of Base URL.  For example, the
test case below would be run against http://news.portal.com/about.html:</p>
<img alt="_images/chapt3_img21_BaseURL_prod.png" class="align-center" src="_images/chapt3_img21_BaseURL_prod.png">
<p>This same test case with a modified Base URL setting would be run against
http://beta.news.portal.com/about.html:</p>
<img alt="_images/chapt3_img22_BaseURL_beta.png" class="align-center" src="_images/chapt3_img22_BaseURL_beta.png">
</div>
<div class="section" id="selenium-commands-selenese">
<span id="selenese"></span><h2>Selenium Commands – “Selenese”<a class="headerlink" href="#selenium-commands-selenese" title="Permalink to this headline">¶</a></h2>
<p>Selenium commands, often called <em>selenese</em>, are the set of commands that run
your tests.  A sequence of these commands is a <em>test script</em>.  Here we explain
those commands in detail, and we present the many choices you have in testing
your web application when using Selenium.</p>
<p>Selenium provides a rich set of commands for fully testing your web-app
in virtually any way you can imagine. The command set is often called
<em>selenese</em>. These commands essentially create a testing language.</p>
<p>In selenese, one can test the existence of UI elements based
on their HTML tags, test for specific content, test for broken links,
input fields, selection list options, submitting forms, and table data among
other things. In addition Selenium commands support testing of window size,
mouse position, alerts, Ajax functionality, pop up windows, event handling,
and many other web-application features. The <a class="reference external" href="http://release.seleniumhq.org/selenium-core/1.0.1/reference.html">Command Reference</a> lists all
the available commands.</p>
<p>A <em>command</em> tells Selenium what to do. Selenium commands come in
three “flavors”: <strong>Actions</strong>, <strong>Accessors</strong>, and <strong>Assertions</strong>.</p>
<ul>
<li><p class="first"><strong>Actions</strong> are commands that generally manipulate the state of the
application. They do things like “click this link” and “select that option”.
If an Action fails, or has an error, the execution of the current test is
stopped.</p>
<p>Many Actions can be called with the “AndWait” suffix, e.g. “clickAndWait”.
This suffix tells Selenium that the action will cause the browser to make a
call to the server, and that Selenium should wait for a new page to load.</p>
</li>
<li><p class="first"><strong>Accessors</strong> examine the state of the application and store the results in
variables, e.g. “storeTitle”. They are also used to automatically generate
Assertions.</p>
</li>
<li><p class="first"><strong>Assertions</strong> are like Accessors, but they verify that the state of the
application conforms to what is expected. Examples include “make sure the
page title is X” and “verify that this checkbox is checked”.</p>
<p>All Selenium Assertions can be used in 3 modes: “assert”, “verify”, and ”
waitFor”. For example, you can “assertText”, “verifyText” and “waitForText”.
When an “assert” fails, the test is aborted. When a “verify” fails, the test
will continue execution, logging the failure. This allows a single “assert”
to ensure that the application is on the correct page, followed by a bunch of
“verify” assertions to test form field values, labels, etc.</p>
<p>“waitFor” commands wait for some condition to become true (which can be
useful for testing Ajax applications). They will succeed immediately if the
condition is already true. However, they will fail and halt the test if the
condition does not become true within the current timeout setting (see the
setTimeout action below).</p>
</li>
</ul>
</div>
<div class="section" id="script-syntax">
<h2>Script Syntax<a class="headerlink" href="#script-syntax" title="Permalink to this headline">¶</a></h2>
<p>Selenium commands are simple, they consist of the command and two parameters.
For example:</p>
<table border="1" class="docutils">
<colgroup>
<col width="38%">
<col width="42%">
<col width="19%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>verifyText</td>
<td>//div//a[2]</td>
<td>Login</td>
</tr>
</tbody>
</table>
<p>The parameters are not always required; it depends on the command. In some
cases both are required, in others one parameter is required, and in still
others the command may take no parameters at all. Here are a couple more
examples:</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%">
<col width="22%">
<col width="45%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>goBackAndWait</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyTextPresent</td>
<td>&nbsp;</td>
<td>Welcome to My Home Page</td>
</tr>
<tr class="row-odd"><td>type</td>
<td>id=phone</td>
<td>(555) 666-7066</td>
</tr>
<tr class="row-even"><td>type</td>
<td>id=address1</td>
<td>${myVariableAddress}</td>
</tr>
</tbody>
</table>
<p>The command reference describes the parameter requirements for each command.</p>
<p>Parameters vary, however they are typically:</p>
<ul class="simple">
<li>a <em>locator</em> for identifying a UI element within a page.</li>
<li>a <em>text pattern</em> for verifying or asserting expected page content</li>
<li>a <em>text pattern</em> or a selenium variable for entering text in an input field
or for selecting an option from an option list.</li>
</ul>
<p>Locators, text patterns,
selenium variables, and the commands themselves are described in considerable
detail in the section on Selenium Commands.</p>
<p>Selenium scripts that will be run from Selenium-IDE will be stored in an HTML
text file format. This consists of an HTML table with three columns. The first
column identifies the Selenium command, the second is a target, and the
final column contains a value. The second and third columns may not require
values depending on the chosen Selenium command, but they should be present.
Each table row represents a new Selenium command. Here is an example of a test
that opens a page, asserts the page title and then verifies some content on the
page:</p>
<div class="highlight-html"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">table</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>open<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>/download/<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>assertTitle<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>Downloads<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>verifyText<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>//h2<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>Downloads<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">table</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>Rendered as a table in a browser this would look like the following:</p>
<table border="1" class="docutils">
<colgroup>
<col width="37%">
<col width="33%">
<col width="30%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>open</td>
<td>/download/</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>assertTitle</td>
<td>&nbsp;</td>
<td>Downloads</td>
</tr>
<tr class="row-odd"><td>verifyText</td>
<td>//h2</td>
<td>Downloads</td>
</tr>
</tbody>
</table>
<p>The Selenese HTML syntax can be used to write and run tests without requiring
knowledge of a programming language.  With a basic knowledge of selenese and
Selenium-IDE you can quickly produce and run testcases.</p>
</div>
<div class="section" id="test-suites">
<h2>Test Suites<a class="headerlink" href="#test-suites" title="Permalink to this headline">¶</a></h2>
<p>A test suite is a collection of tests.  Often one will run all the tests in a
test suite as one continuous batch-job.</p>
<p>When using Selenium-IDE, test suites also can be defined using a simple HTML
file.  The syntax again is simple.  An HTML table defines a list of tests where
each row defines the filesystem path to each test.  An example tells it all.</p>
<div class="highlight-html"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>Test Suite Function Tests - Priority 1<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">table</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">b</span><span class="p">&gt;</span>Suite Of Tests<span class="p">&lt;/</span><span class="nt">b</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./Login.html"</span><span class="p">&gt;</span>Login<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./SearchValues.html"</span><span class="p">&gt;</span>Test Searching for Values<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./SaveValues.html"</span><span class="p">&gt;</span>Test Save<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">table</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</div>
<p>A file similar to this would allow running the tests all at once, one after
another, from the Selenium-IDE.</p>
<p>Test suites can also be maintained when using Selenium-RC.  This is done via
programming and can be done a number of ways.  Commonly Junit is used to
maintain a test suite if one is using Selenium-RC with Java.  Additionally, if
C# is the chosen language, Nunit could be employed.  If using an interpreted
language like Python with Selenium-RC then some simple programming would be
involved in setting up a test suite.  Since the whole reason for using Selenium-RC
is to make use of programming logic for your testing this usually isn’t a
problem.</p>
</div>
<div class="section" id="commonly-used-selenium-commands">
<h2>Commonly Used Selenium Commands<a class="headerlink" href="#commonly-used-selenium-commands" title="Permalink to this headline">¶</a></h2>
<p>To conclude our introduction of Selenium, we’ll show you a few typical Selenium
commands.  These are probably the most commonly used commands for building tests.</p>
<dl class="docutils">
<dt>open</dt>
<dd>opens a page using a URL.</dd>
<dt>click/clickAndWait</dt>
<dd>performs a click operation, and optionally waits for a new page to load.</dd>
<dt>verifyTitle/assertTitle</dt>
<dd>verifies an expected page title.</dd>
<dt>verifyTextPresent</dt>
<dd>verifies expected text is somewhere on the page.</dd>
<dt>verifyElementPresent</dt>
<dd>verifies an expected UI element, as defined by its HTML tag, is present on
the page.</dd>
<dt>verifyText</dt>
<dd>verifies expected text and its corresponding HTML tag are present on the page.</dd>
<dt>verifyTable</dt>
<dd>verifies a table’s expected contents.</dd>
<dt>waitForPageToLoad</dt>
<dd>pauses execution until an expected new page loads.  Called automatically when
clickAndWait is used.</dd>
<dt>waitForElementPresent</dt>
<dd>pauses execution until an expected UI element, as defined by its HTML tag,
is present on the page.</dd>
</dl>
</div>
<div class="section" id="verifying-page-elements">
<h2>Verifying Page Elements<a class="headerlink" href="#verifying-page-elements" title="Permalink to this headline">¶</a></h2>
<p>Verifying UI elements on a web page is probably the most common feature of
your automated tests.  Selenese allows multiple ways of checking for UI
elements.  It is important that you understand these different methods because
these methods define what you are actually testing.</p>
<p>For example, will you test that…</p>
<ol class="loweralpha simple">
<li>an element is present somewhere on the page?</li>
<li>specific text is somewhere on the page?</li>
<li>specific text is at a specific location on the page?</li>
</ol>
<p>For example, if you are testing a text heading, the text and its position
at the top of the page are probably relevant for your test.  If, however, you
are testing for the existence of an image on the home page, and the
web designers frequently change the specific image file along with its position
on the page, then you only want to test that <em>an image</em> (as opposed to the
specific image file) exists <em>somewhere on the page</em>.</p>
</div>
<div class="section" id="assertion-or-verification">
<h2>Assertion or Verification?<a class="headerlink" href="#assertion-or-verification" title="Permalink to this headline">¶</a></h2>
<p>Choosing between “assert” and “verify” comes down to convenience and
management of failures. There’s very little point checking that the first
paragraph on the page is the correct one if your test has already failed when
checking that the browser is displaying the expected page. If you’re not on
the correct page, you’ll probably want to abort your test case so that you can
investigate the cause and fix the issue(s) promptly. On the other hand, you
may want to check many attributes of a page without aborting the test case on
the first failure as this will allow you to review all failures on the page
and take the appropriate action. Effectively an “assert” will fail the test
and abort the current test case, whereas a “verify” will fail the test and
continue to run the test case.</p>
<p>The best use of this feature is to logically group your test commands, and
start each group with an “assert” followed by one or more “verify” test
commands. An example follows:</p>
<table border="1" class="docutils">
<colgroup>
<col width="35%">
<col width="29%">
<col width="35%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>open</td>
<td>/download/</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>assertTitle</td>
<td>Downloads</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyText</td>
<td>//h2</td>
<td>Downloads</td>
</tr>
<tr class="row-odd"><td>assertTable</td>
<td>1.2.1</td>
<td>Selenium IDE</td>
</tr>
<tr class="row-even"><td>verifyTable</td>
<td>1.2.2</td>
<td>June 3, 2008</td>
</tr>
<tr class="row-odd"><td>verifyTable</td>
<td>1.2.3</td>
<td>1.0 beta 2</td>
</tr>
</tbody>
</table>
<p>The above example first opens a page and then “asserts” that the correct page
is loaded by comparing the title with the expected value. Only if this passes
will the following command run and “verify” that the text is present in the
expected location. The test case then “asserts” the first column in the second
row of the first table contains the expected value, and only if this passed will
the remaining cells in that row be “verified”.</p>
<div class="section" id="verifytextpresent">
<h3>verifyTextPresent<a class="headerlink" href="#verifytextpresent" title="Permalink to this headline">¶</a></h3>
<p>The command <code class="docutils literal"><span class="pre">verifyTextPresent</span></code> is used to verify <em>specific text exists
somewhere on the page</em>.  It takes a single argument–the text pattern to be
verified.  For example:</p>
<table border="1" class="docutils">
<colgroup>
<col width="36%">
<col width="38%">
<col width="26%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>verifyTextPresent</td>
<td>Marketing Analysis</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>This would cause Selenium to search for, and verify, that the text string
“Marketing Analysis” appears somewhere on the page currently being tested. Use
<code class="docutils literal"><span class="pre">verifyTextPresent</span></code> when you are interested in only the text
itself being present on the page.  Do not use this when you also need to test
where the text occurs on the page.</p>
</div>
<div class="section" id="verifyelementpresent">
<h3>verifyElementPresent<a class="headerlink" href="#verifyelementpresent" title="Permalink to this headline">¶</a></h3>
<p>Use this command when you must test for the presence of a specific UI
element, rather than its content.  This verification does not check the text,
only the HTML tag.  One common use is to check for the presence of an image.</p>
<table border="1" class="docutils">
<colgroup>
<col width="40%">
<col width="36%">
<col width="24%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>verifyElementPresent</td>
<td>//div/p/img</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>This command verifies that an image, specified by the existence of an &lt;img&gt;
HTML tag, is present on the page, and that it follows a &lt;div&gt; tag and a &lt;p&gt; tag.
The first (and only) parameter is a <em>locator</em> for telling the Selenese command how to
find the element.  Locators are explained in the next section.</p>
<p><code class="docutils literal"><span class="pre">verifyElementPresent</span></code> can be used to check the existence of any HTML tag
within the page. You can check the existence of links, paragraphs, divisions
&lt;div&gt;, etc.  Here are a few more examples.</p>
<table border="1" class="docutils">
<colgroup>
<col width="32%">
<col width="48%">
<col width="19%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>verifyElementPresent</td>
<td>//div/p</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyElementPresent</td>
<td>//div/a</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyElementPresent</td>
<td>id=Login</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyElementPresent</td>
<td>link=Go to Marketing Research</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyElementPresent</td>
<td>//a[2]</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyElementPresent</td>
<td>//head/title</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>These examples illustrate the variety of ways a UI element may be tested.
Again, locators are explained in the next section.</p>
</div>
<div class="section" id="verifytext">
<h3>verifyText<a class="headerlink" href="#verifytext" title="Permalink to this headline">¶</a></h3>
<p>Use <code class="docutils literal"><span class="pre">verifyText</span></code> when both the text and its UI element must be tested.
<code class="docutils literal"><span class="pre">verifyText</span></code> must use a locator.  If you choose an <em>XPath</em> or <em>DOM</em>
locator, you can verify that specific text appears at a specific location on the
page relative to other UI components on the page.</p>
<table border="1" class="docutils">
<colgroup>
<col width="11%">
<col width="20%">
<col width="69%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>verifyText</td>
<td>//table/tr/td/div/p</td>
<td>This is my text and it occurs right after the div inside the table.</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="locating-elements">
<span id="locators-section"></span><h2>Locating Elements<a class="headerlink" href="#locating-elements" title="Permalink to this headline">¶</a></h2>
<p>For many Selenium commands, a target is required. This target identifies an
element in the content of the web application, and consists of the location
strategy followed by the location in the format <code class="docutils literal"><span class="pre">locatorType=location</span></code>. The
locator type can be omitted in many cases.
The various locator types
are explained below with examples for each.</p>
<div class="section" id="locating-by-identifier">
<h3>Locating by Identifier<a class="headerlink" href="#locating-by-identifier" title="Permalink to this headline">¶</a></h3>
<p>This is probably the most common method of locating elements and is the
catch-all default when no recognized locator type is used. With this strategy,
the first element with the id attribute value matching the location will be used. If
no element has a matching id attribute, then the first element with a name
attribute matching the location will be used.</p>
<p>For instance, your page source could have id and name attributes
as follows:</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7
8
9</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
  <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
 <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<p>The following locator strategies would return the elements from the HTML
snippet above indicated by line number:</p>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">identifier=loginForm</span></code> (3)</li>
<li><code class="docutils literal"><span class="pre">identifier=password</span></code> (5)</li>
<li><code class="docutils literal"><span class="pre">identifier=continue</span></code> (6)</li>
<li><code class="docutils literal"><span class="pre">continue</span></code> (6)</li>
</ul>
<p>Since the <code class="docutils literal"><span class="pre">identifier</span></code> type of locator is the default, the <code class="docutils literal"><span class="pre">identifier=</span></code>
in the first three examples above is not necessary.</p>
<div class="section" id="locating-by-id">
<h4>Locating by Id<a class="headerlink" href="#locating-by-id" title="Permalink to this headline">¶</a></h4>
<p>This type of locator is more limited than the identifier locator type, but
also more explicit. Use this when you know an element’s id attribute.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Clear"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
  <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">id=loginForm</span></code> (3)</li>
</ul>
</div>
<div class="section" id="locating-by-name">
<h4>Locating by Name<a class="headerlink" href="#locating-by-name" title="Permalink to this headline">¶</a></h4>
<p>The name locator type will locate the first element with a matching name
attribute. If multiple elements have the same value for a name attribute, then
you can use filters to further refine your location strategy. The default
filter type is value (matching the value attribute).</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Clear"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
 <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">name=username</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">name=continue</span> <span class="pre">value=Clear</span></code> (7)</li>
<li><code class="docutils literal"><span class="pre">name=continue</span> <span class="pre">Clear</span></code> (7)</li>
<li><code class="docutils literal"><span class="pre">name=continue</span> <span class="pre">type=button</span></code> (7)</li>
</ul>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Unlike some types of XPath and DOM locators, the three
types of locators above allow Selenium to test a UI element independent
of its location on
the page.  So if the page structure and organization is altered, the test
will still pass.  You may or may not want to also test whether the page
structure changes.  In the case where web designers frequently alter the
page, but its functionality must be regression tested, testing via id and
name attributes, or really via any HTML property, becomes very important.</p>
</div>
</div>
<div class="section" id="locating-by-xpath">
<h4>Locating by XPath<a class="headerlink" href="#locating-by-xpath" title="Permalink to this headline">¶</a></h4>
<p>XPath is the language used for locating nodes in an XML document. As HTML can
be an implementation of XML (XHTML), Selenium users can leverage this powerful
language to target elements in their web applications. XPath extends beyond (as
well as supporting) the simple methods of locating by id or name
attributes, and opens up all sorts of new possibilities such as locating the
third checkbox on the page.</p>
<p>One of the main reasons for using XPath is when you don’t have a suitable id
or name attribute for the element you wish to locate. You can use XPath to
either locate the element in absolute terms (not advised), or relative to an
element that does have an id or name attribute.  XPath locators can also be
used to specify elements via attributes other than id and name.</p>
<p>Absolute XPaths contain the location of all elements from the root (html) and
as a result are likely to fail with only the slightest adjustment to the
application. By finding a nearby element with an id or name attribute (ideally
a parent element) you can locate your target element based on the relationship.
This is much less likely to change and can make your tests more robust.</p>
<p>Since only <code class="docutils literal"><span class="pre">xpath</span></code> locators start with “//”, it is not necessary to include
the <code class="docutils literal"><span class="pre">xpath=</span></code> label when specifying an XPath locator.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Clear"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
 <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">xpath=/html/body/form[1]</span></code> (3) - <em>Absolute path (would break if the HTML was
changed only slightly)</em></li>
<li><code class="docutils literal"><span class="pre">//form[1]</span></code> (3) - <em>First form element in the HTML</em></li>
<li><code class="docutils literal"><span class="pre">xpath=//form[@id='loginForm']</span></code> (3) - <em>The form element with attribute named ‘id’ and the value ‘loginForm’</em></li>
<li><code class="docutils literal"><span class="pre">xpath=//form[input/@name='username']</span></code> (3) - <em>First form element with an input child
element with attribute named ‘name’ and the value ‘username’</em></li>
<li><code class="docutils literal"><span class="pre">//input[@name='username']</span></code> (4) - <em>First input element with attribute named ‘name’ and the value
‘username’</em></li>
<li><code class="docutils literal"><span class="pre">//form[@id='loginForm']/input[1]</span></code> (4) - <em>First input child element of the
form element with attribute named ‘id’ and the value ‘loginForm’</em></li>
<li><code class="docutils literal"><span class="pre">//input[@name='continue'][@type='button']</span></code> (7) - <em>Input with attribute named ‘name’ and the value ‘continue’
and attribute named ‘type’ and the value ‘button’</em></li>
<li><code class="docutils literal"><span class="pre">//form[@id='loginForm']/input[4]</span></code> (7) - <em>Fourth input child element of the
form element with attribute named ‘id’ and value ‘loginForm’</em></li>
</ul>
<p>These examples cover some basics, but in order to learn more, the
following references are recommended:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.w3schools.com/xml/xpath_intro.asp">W3Schools XPath Tutorial</a></li>
<li><a class="reference external" href="http://www.w3.org/TR/xpath">W3C XPath Recommendation</a></li>
</ul>
<p>There are also a couple of very useful Firefox Add-ons that can assist in
discovering the XPath of an element:</p>
<ul class="simple">
<li><a class="reference external" href="https://addons.mozilla.org/en-US/firefox/addon/1095?id=1095">XPath Checker</a> - suggests
XPath and can be used to test XPath results.</li>
<li><a class="reference external" href="https://addons.mozilla.org/en-US/firefox/addon/1843">Firebug</a> -  XPath
suggestions are just one of the many powerful features of this very useful add-on.</li>
</ul>
</div>
<div class="section" id="locating-hyperlinks-by-link-text">
<h4>Locating Hyperlinks by Link Text<a class="headerlink" href="#locating-hyperlinks-by-link-text" title="Permalink to this headline">¶</a></h4>
<p>This is a simple method of locating a hyperlink in your web page by using the
text of the link. If two links with the same text are present, then the first
match will be used.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3
4
5
6
7</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">p</span><span class="p">&gt;</span>Are you sure you want to do this?<span class="p">&lt;/</span><span class="nt">p</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"continue.html"</span><span class="p">&gt;</span>Continue<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"cancel.html"</span><span class="p">&gt;</span>Cancel<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">link=Continue</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">link=Cancel</span></code> (5)</li>
</ul>
</div>
<div class="section" id="locating-by-dom">
<h4>Locating by DOM<a class="headerlink" href="#locating-by-dom" title="Permalink to this headline">¶</a></h4>
<p>The Document Object Model represents an HTML document and can be accessed
using JavaScript. This location strategy takes JavaScript that evaluates to
an element on the page, which can be simply the element’s location using the
hierarchical dotted notation.</p>
<p>Since only <code class="docutils literal"><span class="pre">dom</span></code> locators start with “document”, it is not necessary to include
the <code class="docutils literal"><span class="pre">dom=</span></code> label when specifying a DOM locator.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Clear"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
 <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">dom=document.getElementById('loginForm')</span></code> (3)</li>
<li><code class="docutils literal"><span class="pre">dom=document.forms['loginForm']</span></code> (3)</li>
<li><code class="docutils literal"><span class="pre">dom=document.forms[0]</span></code> (3)</li>
<li><code class="docutils literal"><span class="pre">document.forms[0].username</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">document.forms[0].elements['username']</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">document.forms[0].elements[0]</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">document.forms[0].elements[3]</span></code> (7)</li>
</ul>
<p>You can use Selenium itself as well as other sites and extensions to explore
the DOM of your web application. A good reference exists on <a class="reference external" href="http://www.w3schools.com/js/js_htmldom.asp">W3Schools</a>.</p>
</div>
<div class="section" id="locating-by-css">
<h4>Locating by CSS<a class="headerlink" href="#locating-by-css" title="Permalink to this headline">¶</a></h4>
<p>CSS (Cascading Style Sheets) is a language for describing the rendering of HTML
and XML documents. CSS uses Selectors for binding style properties to elements
in the document. These Selectors can be used by Selenium as another locating
strategy.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10</pre></div></td><td class="code"><div class="highlight"><pre><span></span> <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
   <span class="p">&lt;</span><span class="nt">form</span> <span class="na">id</span><span class="o">=</span><span class="s">"loginForm"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">class</span><span class="o">=</span><span class="s">"required"</span> <span class="na">name</span><span class="o">=</span><span class="s">"username"</span> <span class="na">type</span><span class="o">=</span><span class="s">"text"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">class</span><span class="o">=</span><span class="s">"required passfield"</span> <span class="na">name</span><span class="o">=</span><span class="s">"password"</span> <span class="na">type</span><span class="o">=</span><span class="s">"password"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"submit"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Login"</span> <span class="p">/&gt;</span>
    <span class="p">&lt;</span><span class="nt">input</span> <span class="na">name</span><span class="o">=</span><span class="s">"continue"</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Clear"</span> <span class="p">/&gt;</span>
   <span class="p">&lt;/</span><span class="nt">form</span><span class="p">&gt;</span>
 <span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
 <span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<ul class="simple">
<li><code class="docutils literal"><span class="pre">css=form#loginForm</span></code> (3)</li>
<li><code class="docutils literal"><span class="pre">css=input[name="username"]</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">css=input.required[type="text"]</span></code> (4)</li>
<li><code class="docutils literal"><span class="pre">css=input.passfield</span></code> (5)</li>
<li><code class="docutils literal"><span class="pre">css=#loginForm</span> <span class="pre">input[type="button"]</span></code> (7)</li>
<li><code class="docutils literal"><span class="pre">css=#loginForm</span> <span class="pre">input:nth-child(2)</span></code> (5)</li>
</ul>
<p>For more information about CSS Selectors, the best place to go is <a class="reference external" href="http://www.w3.org/TR/css3-selectors/">the W3C
publication</a>.  You’ll find additional
references there.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Most experienced Selenium users recommend CSS as their locating
strategy of choice as it’s considerably faster than XPath and can find the
most complicated objects in an intrinsic HTML document.</p>
</div>
</div>
<div class="section" id="implicit-locators">
<h4>Implicit Locators<a class="headerlink" href="#implicit-locators" title="Permalink to this headline">¶</a></h4>
<p>You can choose to omit the locator type in the following situations:</p>
<blockquote>
<div><ul class="simple">
<li>Locators without an explicitly defined locator strategy will default
to using the identifier locator strategy. See <a class="reference internal" href="#locating-by-identifier">Locating by Identifier</a>.</li>
<li>Locators starting with “//” will use the XPath locator strategy.
See <a class="reference internal" href="#locating-by-xpath">Locating by XPath</a>.</li>
<li>Locators starting with “document” will use the DOM locator strategy.
See <a class="reference internal" href="#locating-by-dom">Locating by DOM</a></li>
</ul>
</div></blockquote>
</div>
</div>
</div>
<div class="section" id="matching-text-patterns">
<span id="patterns-section"></span><h2>Matching Text Patterns<a class="headerlink" href="#matching-text-patterns" title="Permalink to this headline">¶</a></h2>
<p>Like locators, <em>patterns</em> are a type of parameter frequently required by Selenese
commands.  Examples of commands which require patterns are <strong>verifyTextPresent</strong>,
<strong>verifyTitle</strong>, <strong>verifyAlert</strong>, <strong>assertConfirmation</strong>, <strong>verifyText</strong>, and
<strong>verifyPrompt</strong>.  And as has been mentioned above, link locators can utilize
a pattern.  Patterns allow you to <em>describe</em>, via the use of special characters,
what text is expected rather than having to specify that text exactly.</p>
<p>There are three types of patterns: <em>globbing</em>, <em>regular expressions</em>, and <em>exact</em>.</p>
<div class="section" id="globbing-patterns">
<h3>Globbing Patterns<a class="headerlink" href="#globbing-patterns" title="Permalink to this headline">¶</a></h3>
<p>Most people are familiar with globbing as it is utilized in
filename expansion at a DOS or Unix/Linux command line such as <code class="docutils literal"><span class="pre">ls</span> <span class="pre">*.c</span></code>.
In this case, globbing is used to display all the files ending with a <code class="docutils literal"><span class="pre">.c</span></code>
extension that exist in the current directory.  Globbing is fairly limited.
Only two special characters are supported in the Selenium implementation:</p>
<blockquote>
<div><p><strong>*</strong> which translates to “match anything,” i.e., nothing, a single character, or many characters.</p>
<p><strong>[ ]</strong> (<em>character class</em>) which translates to “match any single character
found inside the square brackets.” A dash (hyphen) can be used as a shorthand
to specify a range of characters (which are contiguous in the ASCII character
set).  A few examples will make the functionality of a character class clear:</p>
<p><code class="docutils literal"><span class="pre">[aeiou]</span></code> matches any lowercase vowel</p>
<p><code class="docutils literal"><span class="pre">[0-9]</span></code> matches any digit</p>
<p><code class="docutils literal"><span class="pre">[a-zA-Z0-9]</span></code> matches any alphanumeric character</p>
</div></blockquote>
<p>In most other contexts, globbing includes a third special character, the <strong>?</strong>.
However, Selenium globbing patterns only support the asterisk and character
class.</p>
<p>To specify a globbing pattern parameter for a Selenese command, you can
prefix the pattern with a <strong>glob:</strong> label.  However, because globbing
patterns are the default, you can also omit the label and specify just the
pattern itself.</p>
<p>Below is an example of two commands that use globbing patterns.  The
actual link text on the page being tested
was “Film/Television Department”; by using a pattern
rather than the exact text, the <strong>click</strong> command will work even if the
link text is changed to “Film &amp; Television Department” or “Film and Television
Department”.  The glob pattern’s asterisk will match “anything or nothing”
between the word “Film” and the word “Television”.</p>
<table border="1" class="docutils">
<colgroup>
<col width="20%">
<col width="64%">
<col width="16%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>click</td>
<td>link=glob:Film*Television Department</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyTitle</td>
<td>glob:*Film*Television*</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The actual title of the page reached by clicking on the link was “De Anza Film And
Television Department - Menu”.  By using a pattern rather than the exact
text, the <code class="docutils literal"><span class="pre">verifyTitle</span></code> will pass as long as the two words “Film” and “Television” appear
(in that order) anywhere in the page’s title.  For example, if
the page’s owner should shorten
the title to just “Film &amp; Television Department,” the test would still pass.
Using a pattern for both a link and a simple test that the link worked (such as
the <code class="docutils literal"><span class="pre">verifyTitle</span></code> above does) can greatly reduce the maintenance for such
test cases.</p>
<div class="section" id="regular-expression-patterns">
<h4>Regular Expression Patterns<a class="headerlink" href="#regular-expression-patterns" title="Permalink to this headline">¶</a></h4>
<p><em>Regular expression</em> patterns are the most powerful of the three types
of patterns that Selenese supports.  Regular expressions
are also supported by most high-level programming languages, many text
editors, and a host of tools, including the Linux/Unix command-line
utilities <strong>grep</strong>, <strong>sed</strong>, and <strong>awk</strong>.  In Selenese, regular
expression patterns allow a user to perform many tasks that would
be very difficult otherwise.  For example, suppose your test needed
to ensure that a particular table cell contained nothing but a number.
<code class="docutils literal"><span class="pre">regexp:</span> <span class="pre">[0-9]+</span></code> is a simple pattern that will match a decimal number of any length.</p>
<p>Whereas Selenese globbing patterns support only the <strong>*</strong>
and <strong>[ ]</strong> (character
class) features, Selenese regular expression patterns offer the same
wide array of special characters that exist in JavaScript.  Below
are a subset of those special characters:</p>
<table border="1" class="docutils">
<colgroup>
<col width="16%">
<col width="84%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head">PATTERN</th>
<th class="head">MATCH</th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>.</td>
<td>any single character</td>
</tr>
<tr class="row-odd"><td>[ ]</td>
<td>character class: any single character that appears inside the brackets</td>
</tr>
<tr class="row-even"><td>*</td>
<td>quantifier: 0 or more of the preceding character (or group)</td>
</tr>
<tr class="row-odd"><td>+</td>
<td>quantifier: 1 or more of the preceding character (or group)</td>
</tr>
<tr class="row-even"><td>?</td>
<td>quantifier: 0 or 1 of the preceding character (or group)</td>
</tr>
<tr class="row-odd"><td>{1,5}</td>
<td>quantifier: 1 through 5 of the preceding character (or group)</td>
</tr>
<tr class="row-even"><td>|</td>
<td>alternation: the character/group on the left or the character/group on
the right</td>
</tr>
<tr class="row-odd"><td>( )</td>
<td>grouping: often used with alternation and/or quantifier</td>
</tr>
</tbody>
</table>
<p>Regular expression patterns in Selenese need to be prefixed with
either <code class="docutils literal"><span class="pre">regexp:</span></code> or <code class="docutils literal"><span class="pre">regexpi:</span></code>.  The former is case-sensitive; the
latter is case-insensitive.</p>
<p>A few examples will help clarify how regular expression patterns can
be used with Selenese commands.  The first one uses what is probably
the most commonly used regular expression pattern–<strong>.*</strong> (“dot star”).  This
two-character sequence can be translated as “0 or more occurrences of
any character” or more simply, “anything or nothing.”  It is the
equivalent of the one-character globbing pattern <strong>*</strong> (a single asterisk).</p>
<table border="1" class="docutils">
<colgroup>
<col width="19%">
<col width="66%">
<col width="15%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>click</td>
<td>link=regexp:Film.*Television Department</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyTitle</td>
<td>regexp:.*Film.*Television.*</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The example above is functionally equivalent to the earlier example
that used globbing patterns for this same test.  The only differences
are the prefix (<strong>regexp:</strong> instead of <strong>glob:</strong>) and the “anything
or nothing” pattern (<strong>.*</strong> instead of just <strong>*</strong>).</p>
<p>The more complex example below tests that the Yahoo!
Weather page for Anchorage, Alaska contains info on the sunrise time:</p>
<table border="1" class="docutils">
<colgroup>
<col width="24%">
<col width="64%">
<col width="12%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>open</td>
<td><a class="reference external" href="http://weather.yahoo.com/forecast/USAK0012.html">http://weather.yahoo.com/forecast/USAK0012.html</a></td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyTextPresent</td>
<td>regexp:Sunrise: *[0-9]{1,2}:[0-9]{2} [ap]m</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>Let’s examine the regular expression above one part at a time:</p>
<table border="1" class="docutils">
<colgroup>
<col width="21%">
<col width="79%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">Sunrise:</span> <span class="pre">*</span></code></td>
<td>The string <strong>Sunrise:</strong> followed by 0 or more spaces</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">[0-9]{1,2}</span></code></td>
<td>1 or 2 digits (for the hour of the day)</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">:</span></code></td>
<td>The character <strong>:</strong> (no special characters involved)</td>
</tr>
<tr class="row-even"><td><code class="docutils literal"><span class="pre">[0-9]{2}</span></code></td>
<td>2 digits (for the minutes) followed by a space</td>
</tr>
<tr class="row-odd"><td><code class="docutils literal"><span class="pre">[ap]m</span></code></td>
<td>“a” or “p” followed by “m” (am or pm)</td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="exact-patterns">
<h4>Exact Patterns<a class="headerlink" href="#exact-patterns" title="Permalink to this headline">¶</a></h4>
<p>The <strong>exact</strong> type of Selenium pattern is of marginal usefulness.
It uses no special characters at all.  So, if you needed to look for
an actual asterisk character (which is special for both globbing and
regular expression patterns), the <strong>exact</strong> pattern would be one way
to do that.  For example, if you wanted to select an item labeled
“Real *” from a dropdown, the following code might work or it might not.
The asterisk in the <code class="docutils literal"><span class="pre">glob:Real</span> <span class="pre">*</span></code> pattern will match anything or nothing.
So, if there was an earlier select option labeled “Real Numbers,” it would
be the option selected rather than the “Real *” option.</p>
<table border="1" class="docutils">
<colgroup>
<col width="18%">
<col width="60%">
<col width="22%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>select</td>
<td>//select</td>
<td>glob:Real *</td>
</tr>
</tbody>
</table>
<p>In order to ensure that the “Real *” item would be selected, the <code class="docutils literal"><span class="pre">exact:</span></code>
prefix could be used to create an <strong>exact</strong> pattern as shown below:</p>
<table border="1" class="docutils">
<colgroup>
<col width="18%">
<col width="60%">
<col width="22%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>select</td>
<td>//select</td>
<td>exact:Real *</td>
</tr>
</tbody>
</table>
<p>But the same effect could be achieved via escaping the asterisk in a
regular expression pattern:</p>
<table border="1" class="docutils">
<colgroup>
<col width="17%">
<col width="57%">
<col width="25%">
</colgroup>
<tbody valign="top">
<tr class="row-odd"><td>select</td>
<td>//select</td>
<td>regexp:Real \*</td>
</tr>
</tbody>
</table>
<p>It’s rather unlikely that most testers will ever need to look for
an asterisk or a set of square brackets with characters inside them (the
character class for globbing patterns).  Thus, globbing patterns and
regular expression patterns are sufficient for the vast majority of us.</p>
</div>
</div>
</div>
<div class="section" id="the-andwait-commands">
<h2>The “AndWait” Commands<a class="headerlink" href="#the-andwait-commands" title="Permalink to this headline">¶</a></h2>
<p>The difference between a command and its <em>AndWait</em>
alternative is that the regular command (e.g. <em>click</em>) will do the action and
continue with the following command as fast as it can, while the <em>AndWait</em>
alternative (e.g. <em>clickAndWait</em>) tells Selenium to <strong>wait</strong> for the page to
load after the action has been done.</p>
<p>The <em>AndWait</em> alternative is always used when the action causes the browser to
navigate to another page or reload the present one.</p>
<p>Be aware, if you use an <em>AndWait</em> command for an action that
does not trigger a navigation/refresh, your test will fail. This happens
because Selenium will reach the <em>AndWait</em>’s timeout without seeing any
navigation or refresh being made, causing Selenium to raise a timeout
exception.</p>
</div>
<div class="section" id="the-waitfor-commands-in-ajax-applications">
<span id="waitfor"></span><h2>The waitFor Commands in AJAX applications<a class="headerlink" href="#the-waitfor-commands-in-ajax-applications" title="Permalink to this headline">¶</a></h2>
<p>In AJAX driven web applications, data is retrieved from server without
refreshing the page. Using <em>andWait</em> commands will not work as the page is not
actually refreshed. Pausing the test execution for a certain period of time is
also not a good approach as web element might appear later or earlier than the
stipulated period depending on the system’s responsiveness, load or other
uncontrolled factors of the moment, leading to test failures. The best approach
would be to wait for the needed element in a dynamic period and then continue
the execution as soon as the element is found.</p>
<p>This is done using <em>waitFor</em> commands, as <em>waitForElementPresent</em> or
<em>waitForVisible</em>, which wait dynamically, checking for the desired condition
every second and continuing to the next command in the script as soon as the
condition is met.</p>
</div>
<div class="section" id="sequence-of-evaluation-and-flow-control">
<h2>Sequence of Evaluation and Flow Control<a class="headerlink" href="#sequence-of-evaluation-and-flow-control" title="Permalink to this headline">¶</a></h2>
<p>When a script runs, it simply runs in sequence, one command after another.</p>
<p>Selenese, by itself, does not support condition statements (if-else, etc.) or
iteration (for, while, etc.). Many useful tests can be conducted without flow
control. However, for a functional test of dynamic content, possibly involving
multiple pages, programming logic is often needed.</p>
<p>When flow control is needed, there are three options:</p>
<ol class="loweralpha simple">
<li>Run the script using Selenium-RC and a client library such as Java or
PHP to utilize the programming language’s flow control features.</li>
<li>Run a small JavaScript snippet from within the script using the storeEval command.</li>
<li>Install the <a class="reference internal" href="#goto-sel-ide-js-extension">goto_sel_ide.js extension</a>.</li>
</ol>
<p>Most testers will export the test script into a programming language file that uses the
Selenium-RC API (see the Selenium-IDE chapter).  However, some organizations prefer
to run their scripts from Selenium-IDE whenever possible (for instance, when they have
many junior-level people running tests for them, or when programming skills are
lacking). If this is your case, consider a JavaScript snippet or the goto_sel_ide.js extension.</p>
</div>
<div class="section" id="store-commands-and-selenium-variables">
<h2>Store Commands and Selenium Variables<a class="headerlink" href="#store-commands-and-selenium-variables" title="Permalink to this headline">¶</a></h2>
<p>You can use Selenium variables to store constants at the
beginning of a script.  Also, when combined with a data-driven test design
(discussed in a later section), Selenium variables can be used to store values
passed to your test program from the command-line, from another program, or from
a file.</p>
<p>The plain <em>store</em> command is the most basic of the many store commands and can be used
to simply store a constant value in a selenium variable.  It takes two
parameters, the text value to be stored and a selenium variable.  Use the
standard variable naming conventions of only alphanumeric characters when
choosing a name for your variable.</p>
<table border="1" class="docutils">
<colgroup>
<col width="33%">
<col width="42%">
<col width="25%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>store</td>
<td><a class="reference external" href="mailto:paul%40mysite.org">paul<span>@</span>mysite<span>.</span>org</a></td>
<td>userName</td>
</tr>
</tbody>
</table>
<p>Later in your script, you’ll want to use the stored value of your
variable.  To access the value of a variable, enclose the variable in
curly brackets ({}) and precede it with a dollar sign like this.</p>
<table border="1" class="docutils">
<colgroup>
<col width="34%">
<col width="29%">
<col width="37%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>verifyText</td>
<td>//div/p</td>
<td>${userName}</td>
</tr>
</tbody>
</table>
<p>A common use of variables is for storing input for an input field.</p>
<table border="1" class="docutils">
<colgroup>
<col width="34%">
<col width="29%">
<col width="37%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>type</td>
<td>id=login</td>
<td>${userName}</td>
</tr>
</tbody>
</table>
<p>Selenium variables can be used in either the first or second parameter and
are interpreted by Selenium prior to any other operations performed by the
command.  A Selenium variable may also be used within a locator expression.</p>
<p>An equivalent store command exists for each verify and assert command.  Here
are a couple more commonly used store commands.</p>
<div class="section" id="storeelementpresent">
<h3>storeElementPresent<a class="headerlink" href="#storeelementpresent" title="Permalink to this headline">¶</a></h3>
<p>This corresponds to verifyElementPresent.  It simply stores a boolean value–”true”
or “false”–depending on whether the UI element is found.</p>
</div>
<div class="section" id="storetext">
<h3>storeText<a class="headerlink" href="#storetext" title="Permalink to this headline">¶</a></h3>
<p>StoreText corresponds to verifyText.  It uses a locater to identify specific
page text.  The text, if found, is stored in the variable.  StoreText can be
used to extract text from the page being tested.</p>
</div>
<div class="section" id="storeeval">
<h3>storeEval<a class="headerlink" href="#storeeval" title="Permalink to this headline">¶</a></h3>
<p>This command takes a script as its
first parameter.  Embedding JavaScript within Selenese is covered in the next section.
StoreEval allows the test to store the result of running the script in a variable.</p>
</div>
</div>
<div class="section" id="javascript-and-selenese-parameters">
<h2>JavaScript and Selenese Parameters<a class="headerlink" href="#javascript-and-selenese-parameters" title="Permalink to this headline">¶</a></h2>
<p>JavaScript can be used with two types of Selenese parameters: script
and non-script (usually expressions).  In most cases, you’ll want to access
and/or manipulate a test case variable inside the JavaScript snippet used as
a Selenese parameter.  All variables created in your test case are stored in
a JavaScript <em>associative array</em>.  An associative array has string indexes
rather than sequential numeric indexes.  The associative array containing
your test case’s variables is named <strong>storedVars</strong>.  Whenever you wish to
access or manipulate a variable within a JavaScript snippet, you must refer
to it as <strong>storedVars[‘yourVariableName’]</strong>.</p>
<div class="section" id="javascript-usage-with-script-parameters">
<h3>JavaScript Usage with Script Parameters<a class="headerlink" href="#javascript-usage-with-script-parameters" title="Permalink to this headline">¶</a></h3>
<p>Several Selenese commands specify a <strong>script</strong> parameter including
<strong>assertEval</strong>, <strong>verifyEval</strong>, <strong>storeEval</strong>, and <strong>waitForEval</strong>.
These parameters require no special syntax.  A Selenium-IDE
user would simply place a snippet of JavaScript code into
the  appropriate field, normally the <strong>Target</strong> field (because
a <strong>script</strong> parameter is normally the first or only parameter).</p>
<p>The example below illustrates how a JavaScript snippet
can be used to perform a simple numerical calculation:</p>
<table border="1" class="docutils">
<colgroup>
<col width="21%">
<col width="63%">
<col width="16%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>store</td>
<td>10</td>
<td>hits</td>
</tr>
<tr class="row-odd"><td>storeXpathCount</td>
<td>//blockquote</td>
<td>blockquotes</td>
</tr>
<tr class="row-even"><td>storeEval</td>
<td>storedVars[‘hits’]-storedVars[‘blockquotes’]</td>
<td>paragraphs</td>
</tr>
</tbody>
</table>
<p>This next example illustrates how a JavaScript snippet can include calls to
methods, in this case the JavaScript String object’s <code class="docutils literal"><span class="pre">toUpperCase</span></code> method
and <code class="docutils literal"><span class="pre">toLowerCase</span></code> method.</p>
<table border="1" class="docutils">
<colgroup>
<col width="21%">
<col width="63%">
<col width="16%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>store</td>
<td>Edith Wharton</td>
<td>name</td>
</tr>
<tr class="row-odd"><td>storeEval</td>
<td>storedVars[‘name’].toUpperCase()</td>
<td>uc</td>
</tr>
<tr class="row-even"><td>storeEval</td>
<td>storedVars[‘name’].toLowerCase()</td>
<td>lc</td>
</tr>
</tbody>
</table>
<div class="section" id="javascript-usage-with-non-script-parameters">
<h4>JavaScript Usage with Non-Script Parameters<a class="headerlink" href="#javascript-usage-with-non-script-parameters" title="Permalink to this headline">¶</a></h4>
<p>JavaScript can also be used to help generate values for parameters, even
when the parameter is not specified to be of type <strong>script</strong>.
However, in this case, special syntax is required–the <em>entire</em> parameter value must be prefixed by <code class="docutils literal"><span class="pre">javascript{</span></code> with a trailing <code class="docutils literal"><span class="pre">}</span></code>, which encloses the JavaScript
snippet, as in <code class="docutils literal"><span class="pre">javascript{*yourCodeHere*}</span></code>.
Below is an example in which the <code class="docutils literal"><span class="pre">type</span></code> command’s second parameter
<code class="docutils literal"><span class="pre">value</span></code> is generated via JavaScript code using this special syntax:</p>
<table border="1" class="docutils">
<colgroup>
<col width="14%">
<col width="40%">
<col width="47%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>store</td>
<td>league of nations</td>
<td>searchString</td>
</tr>
<tr class="row-odd"><td>type</td>
<td>q</td>
<td>javascript{storedVars[‘searchString’].toUpperCase()}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
<div class="section" id="echo-the-selenese-print-command">
<h2><em>echo</em> - The Selenese Print Command<a class="headerlink" href="#echo-the-selenese-print-command" title="Permalink to this headline">¶</a></h2>
<p>Selenese has a simple command that allows you to print text to your test’s
output.  This is useful for providing informational progress notes in your
test which display on the console as your test is running.  These notes also can be
used to provide context within your test result reports, which can be useful
for finding where a defect exists on a page in the event your test finds a
problem.  Finally, echo statements can be used to print the contents of
Selenium variables.</p>
</div>
<div class="section" id="alerts-popups-and-multiple-windows">
<h2>Alerts, Popups, and Multiple Windows<a class="headerlink" href="#alerts-popups-and-multiple-windows" title="Permalink to this headline">¶</a></h2>
<p>Suppose that you are testing a page that looks like this.</p>
<div class="highlight-html"><table class="highlighttable"><tbody><tr><td class="linenos"><div class="linenodiv"><pre> 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="cp">&lt;!DOCTYPE HTML&gt;</span>
<span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">script</span> <span class="na">type</span><span class="o">=</span><span class="s">"text/javascript"</span><span class="p">&gt;</span>
    <span class="kd">function</span> <span class="nx">output</span><span class="p">(</span><span class="nx">resultText</span><span class="p">){</span>
      <span class="nb">document</span><span class="p">.</span><span class="nx">getElementById</span><span class="p">(</span><span class="s1">'output'</span><span class="p">).</span><span class="nx">childNodes</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="nx">nodeValue</span><span class="o">=</span><span class="nx">resultText</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kd">function</span> <span class="nx">show_confirm</span><span class="p">(){</span>
      <span class="kd">var</span> <span class="nx">confirmation</span><span class="o">=</span><span class="nx">confirm</span><span class="p">(</span><span class="s2">"Chose an option."</span><span class="p">);</span>
      <span class="k">if</span> <span class="p">(</span><span class="nx">confirmation</span><span class="o">==</span><span class="kc">true</span><span class="p">){</span>
        <span class="nx">output</span><span class="p">(</span><span class="s2">"Confirmed."</span><span class="p">);</span>
      <span class="p">}</span>
      <span class="k">else</span><span class="p">{</span>
        <span class="nx">output</span><span class="p">(</span><span class="s2">"Rejected!"</span><span class="p">);</span>
      <span class="p">}</span>
    <span class="p">}</span>

    <span class="kd">function</span> <span class="nx">show_alert</span><span class="p">(){</span>
      <span class="nx">alert</span><span class="p">(</span><span class="s2">"I'm blocking!"</span><span class="p">);</span>
      <span class="nx">output</span><span class="p">(</span><span class="s2">"Alert is gone."</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="kd">function</span> <span class="nx">show_prompt</span><span class="p">(){</span>
      <span class="kd">var</span> <span class="nx">response</span> <span class="o">=</span> <span class="nx">prompt</span><span class="p">(</span><span class="s2">"What's the best web QA tool?"</span><span class="p">,</span><span class="s2">"Selenium"</span><span class="p">);</span>
      <span class="nx">output</span><span class="p">(</span><span class="nx">response</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="kd">function</span> <span class="nx">open_window</span><span class="p">(</span><span class="nx">windowName</span><span class="p">){</span>
      <span class="nb">window</span><span class="p">.</span><span class="nx">open</span><span class="p">(</span><span class="s2">"newWindow.html"</span><span class="p">,</span><span class="nx">windowName</span><span class="p">);</span>
    <span class="p">}</span>
    <span class="p">&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>

  <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"btnConfirm"</span> <span class="na">onclick</span><span class="o">=</span><span class="s">"show_confirm()"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Show confirm box"</span> <span class="p">/&gt;</span>
  <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"btnAlert"</span> <span class="na">onclick</span><span class="o">=</span><span class="s">"show_alert()"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Show alert"</span> <span class="p">/&gt;</span>
  <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"btnPrompt"</span> <span class="na">onclick</span><span class="o">=</span><span class="s">"show_prompt()"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Show prompt"</span> <span class="p">/&gt;</span>
  <span class="p">&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"newWindow.html"</span> <span class="na">id</span><span class="o">=</span><span class="s">"lnkNewWindow"</span> <span class="na">target</span><span class="o">=</span><span class="s">"_blank"</span><span class="p">&gt;</span>New Window Link<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
  <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"btnNewNamelessWindow"</span> <span class="na">onclick</span><span class="o">=</span><span class="s">"open_window()"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Open Nameless Window"</span> <span class="p">/&gt;</span>
  <span class="p">&lt;</span><span class="nt">input</span> <span class="na">type</span><span class="o">=</span><span class="s">"button"</span> <span class="na">id</span><span class="o">=</span><span class="s">"btnNewNamedWindow"</span> <span class="na">onclick</span><span class="o">=</span><span class="s">"open_window('Mike')"</span> <span class="na">value</span><span class="o">=</span><span class="s">"Open Named Window"</span> <span class="p">/&gt;</span>

  <span class="p">&lt;</span><span class="nt">br</span> <span class="p">/&gt;</span>
  <span class="p">&lt;</span><span class="nt">span</span> <span class="na">id</span><span class="o">=</span><span class="s">"output"</span><span class="p">&gt;</span>
  <span class="p">&lt;/</span><span class="nt">span</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</td></tr></tbody></table></div>
<p>The user must respond to alert/confirm boxes, as well as moving focus to newly
opened popup windows. Fortunately, Selenium can cover JavaScript pop-ups.</p>
<p>But before we begin covering alerts/confirms/prompts in individual detail, it is
helpful to understand the commonality between them. Alerts, confirmation boxes
and prompts all have variations of the following</p>
<table border="1" class="docutils">
<colgroup>
<col width="28%">
<col width="72%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Description</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>assertFoo(<em>pattern</em>)</td>
<td>throws error if <em>pattern</em> doesn’t match the text of the pop-up</td>
</tr>
<tr class="row-odd"><td>assertFooPresent</td>
<td>throws error if pop-up is not available</td>
</tr>
<tr class="row-even"><td>assertFooNotPresent</td>
<td>throws error if any pop-up is present</td>
</tr>
<tr class="row-odd"><td>storeFoo(<em>variable</em>)</td>
<td>stores the text of the pop-up in a variable</td>
</tr>
<tr class="row-even"><td>storeFooPresent(<em>variable</em>)</td>
<td>stores the text of the pop-up in a variable and returns true or false</td>
</tr>
</tbody>
</table>
<p>When running under Selenium, JavaScript pop-ups will not appear. This is because
the function calls are actually being overridden at runtime by Selenium’s own
JavaScript. However, just because you cannot see the pop-up doesn’t mean you don’t
have to deal with it. To handle a pop-up, you must call its <code class="docutils literal"><span class="pre">assertFoo(pattern)</span></code>
function. If you fail to assert the presence of a pop-up your next command will be
blocked and you will get an error similar to the following <code class="docutils literal"><span class="pre">[error]</span> <span class="pre">Error:</span> <span class="pre">There</span>
<span class="pre">was</span> <span class="pre">an</span> <span class="pre">unexpected</span> <span class="pre">Confirmation!</span> <span class="pre">[Chose</span> <span class="pre">an</span> <span class="pre">option.]</span></code></p>
<div class="section" id="alerts">
<h3>Alerts<a class="headerlink" href="#alerts" title="Permalink to this headline">¶</a></h3>
<p>Let’s start with alerts because they are the simplest pop-up to handle. To begin,
open the HTML sample above in a browser and click on the “Show alert” button. You’ll
notice that after you close the alert the text “Alert is gone.” is displayed on the
page. Now run through the same steps with Selenium IDE recording, and verify
the text is added after you close the alert. Your test will look something like
this:</p>
<table border="1" class="docutils">
<colgroup>
<col width="25%">
<col width="60%">
<col width="15%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>open</td>
<td>/</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>click</td>
<td>btnAlert</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>assertAlert</td>
<td>I’m blocking!</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>verifyTextPresent</td>
<td>Alert is gone.</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>You may be thinking “That’s odd, I never tried to assert that alert.” But this is
Selenium-IDE handling and closing the alert for you. If you remove that step and replay
the test you will get the following error <code class="docutils literal"><span class="pre">[error]</span> <span class="pre">Error:</span> <span class="pre">There</span> <span class="pre">was</span> <span class="pre">an</span> <span class="pre">unexpected</span>
<span class="pre">Alert!</span> <span class="pre">[I'm</span> <span class="pre">blocking!]</span></code>. You must include an assertion of the alert to acknowledge
its presence.</p>
<p>If you just want to assert that an alert is present but either don’t know or don’t care
what text it contains, you can use <code class="docutils literal"><span class="pre">assertAlertPresent</span></code>. This will return true or false,
with false halting the test.</p>
</div>
<div class="section" id="confirmations">
<h3>Confirmations<a class="headerlink" href="#confirmations" title="Permalink to this headline">¶</a></h3>
<p>Confirmations behave in much the same way as alerts, with <code class="docutils literal"><span class="pre">assertConfirmation</span></code> and
<code class="docutils literal"><span class="pre">assertConfirmationPresent</span></code> offering the same characteristics as their alert counterparts.
However, by default Selenium will select OK when a confirmation pops up. Try recording
clicking on the “Show confirm box” button in the sample page, but click on the “Cancel” button
in the popup, then assert the output text. Your test may look something like this:</p>
<table border="1" class="docutils">
<colgroup>
<col width="36%">
<col width="51%">
<col width="13%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>open</td>
<td>/</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>click</td>
<td>btnConfirm</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>chooseCancelOnNextConfirmation</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>assertConfirmation</td>
<td>Choose an option.</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyTextPresent</td>
<td>Rejected</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>The <code class="docutils literal"><span class="pre">chooseCancelOnNextConfirmation</span></code> function tells Selenium that all following
confirmation should return false. It can be reset by calling chooseOkOnNextConfirmation.</p>
<p>You may notice that you cannot replay this test, because Selenium complains that there
is an unhandled confirmation. This is because the order of events Selenium-IDE records
causes the click and chooseCancelOnNextConfirmation to be put in the wrong order (it makes sense
if you think about it, Selenium can’t know that you’re cancelling before you open a confirmation)
Simply switch these two commands and your test will run fine.</p>
</div>
<div class="section" id="prompts">
<h3>Prompts<a class="headerlink" href="#prompts" title="Permalink to this headline">¶</a></h3>
<p>Prompts behave in much the same way as alerts, with <code class="docutils literal"><span class="pre">assertPrompt</span></code> and <code class="docutils literal"><span class="pre">assertPromptPresent</span></code> offering the same characteristics as their alert counterparts. By default, Selenium will wait for you to input data when the prompt pops up. Try recording clicking on the “Show prompt” button in the sample page and enter “Selenium” into the prompt. Your test may look something like this:</p>
<table border="1" class="docutils">
<colgroup>
<col width="30%">
<col width="41%">
<col width="30%">
</colgroup>
<thead valign="bottom">
<tr class="row-odd"><th class="head"><strong>Command</strong></th>
<th class="head"><strong>Target</strong></th>
<th class="head"><strong>Value</strong></th>
</tr>
</thead>
<tbody valign="top">
<tr class="row-even"><td>open</td>
<td>/</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>answerOnNextPrompt</td>
<td>Selenium!</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>click</td>
<td>id=btnPrompt</td>
<td>&nbsp;</td>
</tr>
<tr class="row-odd"><td>assertPrompt</td>
<td>What’s the best web QA tool?</td>
<td>&nbsp;</td>
</tr>
<tr class="row-even"><td>verifyTextPresent</td>
<td>Selenium!</td>
<td>&nbsp;</td>
</tr>
</tbody>
</table>
<p>If you choose cancel on the prompt, you may notice that answerOnNextPrompt will simply show a target of blank. Selenium treats cancel and a blank entry on the prompt basically as the same thing.</p>
</div>
</div>
<div class="section" id="debugging">
<h2>Debugging<a class="headerlink" href="#debugging" title="Permalink to this headline">¶</a></h2>
<p>Debugging means finding and fixing errors in your test case.  This is a normal
part of test case development.</p>
<p>We won’t teach debugging here as most new users to Selenium will already have
some basic experience with debugging.  If this is new to you, we recommend
you ask one of the developers in your organization.</p>
<div class="section" id="breakpoints-and-startpoints">
<h3>Breakpoints and Startpoints<a class="headerlink" href="#breakpoints-and-startpoints" title="Permalink to this headline">¶</a></h3>
<p>The Sel-IDE supports the setting of breakpoints and the ability to start and
stop the running of a test case, from any point within the test case.  That is, one
can run up to a specific command in the middle of the test case and inspect how
the test case behaves at that point.  To do this, set a breakpoint on the
command just before the one to be examined.</p>
<p>To set a breakpoint, select a command, right-click, and from the context menu
select <em>Toggle Breakpoint</em>.  Then click the Run button to run your test case from
the beginning up to the breakpoint.</p>
<p>It is also sometimes useful to run a test case from somewhere in the middle to
the end of the test case or up to a breakpoint that follows the starting point.
For example, suppose your test case first logs into the website and then
performs a series of tests and you are trying to debug one of those tests.
However, you only need to login once, but you need to keep rerunning your
tests as you are developing them.  You can login once, then run your test case
from a startpoint placed after the login portion of your test case.  That will
prevent you from having to manually logout each time you rerun your test case.</p>
<p>To set a startpoint, select a command, right-click, and from the context
menu select <em>Set/Clear Start Point</em>.  Then click the Run button to execute the
test case beginning at that startpoint.</p>
</div>
<div class="section" id="stepping-through-a-testcase">
<h3>Stepping Through a Testcase<a class="headerlink" href="#stepping-through-a-testcase" title="Permalink to this headline">¶</a></h3>
<p>To execute a test case one command at a time (“step through” it), follow these
steps:</p>
<ol class="arabic simple">
<li>Start the test case running with the Run button from the toolbar.</li>
</ol>
<img alt="_images/chapt3_img09_Run.png" src="_images/chapt3_img09_Run.png">
<ol class="arabic simple" start="2">
<li>Immediately pause the executing test case with the Pause button.</li>
</ol>
<img alt="_images/chapt3_img10_Pause.png" src="_images/chapt3_img10_Pause.png">
<ol class="arabic simple" start="3">
<li>Repeatedly select the Step button.</li>
</ol>
<img alt="_images/chapt3_img12_Step.png" src="_images/chapt3_img12_Step.png">
</div>
<div class="section" id="find-button">
<h3>Find Button<a class="headerlink" href="#find-button" title="Permalink to this headline">¶</a></h3>
<p>The Find button is used to see which UI element on the currently displayed
webpage (in the browser) is used in the currently selected Selenium command.
This is useful when building a locator for a command’s first parameter (see the
section on <a class="reference internal" href="cn/04_selenese_commands.jsp#locators-section"><span class="std std-ref">locators</span></a> in the Selenium Commands chapter).
It can be used with any command that identifies a UI element on a webpage,
i.e. <em>click</em>, <em>clickAndWait</em>, <em>type</em>, and certain <em>assert</em> and <em>verify</em> commands,
among others.</p>
<p>From Table view, select any command that has a locator parameter.
Click the Find button.
Now look on the webpage: There should be a bright green rectangle
enclosing the element specified by the locator parameter.</p>
</div>
<div class="section" id="page-source-for-debugging">
<h3>Page Source for Debugging<a class="headerlink" href="#page-source-for-debugging" title="Permalink to this headline">¶</a></h3>
<p>Often, when debugging a test case, you simply must look at the page source (the
HTML for the webpage you’re trying to test) to determine a problem.  Firefox
makes this easy.  Simply right-click the webpage and select ‘View-&gt;Page Source.
The HTML opens in a separate window.  Use its Search feature (Edit=&gt;Find)
to search for a keyword to find the HTML for the UI element you’re trying
to test.</p>
<p>Alternatively, select just that portion of the webpage for which you want to
see the source.  Then right-click the webpage and select View Selection
Source.  In this case, the separate HTML window will contain just a small
amount of source, with highlighting on the portion representing your
selection.</p>
</div>
<div class="section" id="locator-assistance">
<h3>Locator Assistance<a class="headerlink" href="#locator-assistance" title="Permalink to this headline">¶</a></h3>
<p>Whenever Selenium-IDE records a locator-type argument, it stores
additional information which allows the user to view other possible
locator-type arguments that could be used instead.  This feature can be
very useful for learning more about locators, and is often needed to help
one build a different type of locator than the type that was recorded.</p>
<p>This locator assistance is presented on the Selenium-IDE window as a drop-down
list accessible at the right end of the Target field
(only when the Target field contains a recorded locator-type argument).
Below is a snapshot showing the
contents of this drop-down for one command.  Note that the first column of
the drop-down provides alternative locators, whereas the second column
indicates the type of each alternative.</p>
<img alt="_images/chapt3_img23_IDE_Locator_Assistance.png" src="_images/chapt3_img23_IDE_Locator_Assistance.png">
</div>
</div>
<div class="section" id="writing-a-test-suite">
<h2>Writing a Test Suite<a class="headerlink" href="#writing-a-test-suite" title="Permalink to this headline">¶</a></h2>
<p>A test suite is a collection of test cases which is displayed in the leftmost
pane in the IDE.
The test suite pane can be manually opened or closed via selecting a small dot
halfway down the right edge of the pane (which is the left edge of the
entire Selenium-IDE window if the pane is closed).</p>
<p>The test suite pane will be automatically opened when an existing test suite
is opened <em>or</em> when the user selects the New Test Case item from the
File menu.  In the latter case, the new test case will appear immediately
below the previous test case.</p>
<p>Selenium-IDE also supports loading pre-existing test cases by using the File
-&gt; Add Test Case menu option.  This allows you to add existing test cases to
a new test suite.</p>
<p>A test suite file is an HTML file containing a one-column table.  Each
cell of each row in the &lt;tbody&gt; section contains a link to a test case.
The example below is of a test suite containing four test cases:</p>
<div class="highlight-html"><div class="highlight"><pre><span></span><span class="p">&lt;</span><span class="nt">html</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">head</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">meta</span> <span class="na">http-equiv</span><span class="o">=</span><span class="s">"Content-Type"</span> <span class="na">content</span><span class="o">=</span><span class="s">"text/html; charset=UTF-8"</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">title</span><span class="p">&gt;</span>Sample Selenium Test Suite<span class="p">&lt;/</span><span class="nt">title</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">head</span><span class="p">&gt;</span>
<span class="p">&lt;</span><span class="nt">body</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">table</span> <span class="na">cellpadding</span><span class="o">=</span><span class="s">"1"</span> <span class="na">cellspacing</span><span class="o">=</span><span class="s">"1"</span> <span class="na">border</span><span class="o">=</span><span class="s">"1"</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">thead</span><span class="p">&gt;</span>
            <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;</span>Test Cases for De Anza A-Z Directory Links<span class="p">&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
        <span class="p">&lt;/</span><span class="nt">thead</span><span class="p">&gt;</span>
    <span class="p">&lt;</span><span class="nt">tbody</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./a.html"</span><span class="p">&gt;</span>A Links<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./b.html"</span><span class="p">&gt;</span>B Links<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./c.html"</span><span class="p">&gt;</span>C Links<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
        <span class="p">&lt;</span><span class="nt">tr</span><span class="p">&gt;&lt;</span><span class="nt">td</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">href</span><span class="o">=</span><span class="s">"./d.html"</span><span class="p">&gt;</span>D Links<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;&lt;/</span><span class="nt">td</span><span class="p">&gt;&lt;/</span><span class="nt">tr</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">tbody</span><span class="p">&gt;</span>
    <span class="p">&lt;/</span><span class="nt">table</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">body</span><span class="p">&gt;</span>
<span class="p">&lt;/</span><span class="nt">html</span><span class="p">&gt;</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Test case files should not have to be co-located with the test suite file
that invokes them.  And on Mac OS and Linux systems, that is indeed the
case.  However, at the time of this writing, a bug prevents Windows users
from being able to place the test cases elsewhere than with the test suite
that invokes them.</p>
</div>
</div>
<div class="section" id="user-extensions">
<h2>User Extensions<a class="headerlink" href="#user-extensions" title="Permalink to this headline">¶</a></h2>
<p>User extensions are JavaScript files that allow one to create his or her own
customizations and features to add additional functionality.  Often this is in
the form of customized commands although this extensibility is not limited to
additional commands.</p>
<p>There are a number of useful <a class="reference external" href="http://wiki.openqa.org/display/SEL/Contributed+User-Extensions">extensions</a> created by users.</p>
<p><em>IMPORTANT:  THIS SECTION IS OUT OF DATE–WE WILL BE REVISING THIS SOON.</em></p>
<p id="goto-sel-ide-js-extension">Perhaps the most popular of all Selenium-IDE extensions
is one which provides flow control in the form of while loops and primitive
conditionals.  This extension is the <a class="reference external" href="http://wiki.openqa.org/download/attachments/379/goto_sel_ide.js">goto_sel_ide.js</a>.  For an example
of how to use the functionality provided by this extension, look at the
<a class="reference external" href="http://51elliot.blogspot.com/2008/02/selenium-ide-goto.html">page</a> created by its author.</p>
<p>To install this extension, put the pathname to its location on your
computer in the <strong>Selenium Core extensions</strong> field of Selenium-IDE’s
Options=&gt;Options=&gt;General tab.</p>
<img alt="_images/chapt3_img32_Extensions_install.png" class="align-center" src="_images/chapt3_img32_Extensions_install.png">
<p>After selecting the <strong>OK</strong> button, you must close and reopen Selenium-IDE
in order for the extensions file to be read.  Any change you make to an
extension will also require you to close and reopen Selenium-IDE.</p>
<p>Information on writing your own extensions can be found near the
bottom of the Selenium <a class="reference external" href="http://release.openqa.org/selenium-core/1.0/reference.html">Reference</a> document.</p>
<p>Sometimes it can prove very useful to debug step by step Selenium IDE and your
User Extension. The only debugger that appears able to debug
XUL/Chrome based extensions is Venkman which is supported in Firefox until version 32 included.
The step by step debug has been verified to work with Firefox 32 and Selenium IDE 2.9.0.</p>
</div>
<div class="section" id="format">
<h2>Format<a class="headerlink" href="#format" title="Permalink to this headline">¶</a></h2>
<p>Format, under the Options menu, allows you to select a language for saving
and displaying the test case.  The default is HTML.</p>
<p>If you will be using Selenium-RC to run your test cases, this feature is used
to translate your test case into a programming language. Select the
language, e.g. Java, PHP, you will be using with Selenium-RC for developing
your test programs.  Then simply save the test case using File=&gt;Export Test Case As.
Your test case will be translated into a series of functions in the language you
choose. Essentially, program code supporting your test is generated for you
by Selenium-IDE.</p>
<p>Also, note that if the generated code does not suit your needs, you can alter
it by editing a configuration file which defines the generation process.
Each supported language has configuration settings which are editable.  This
is under the Options=&gt;Options=&gt;Formats tab.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">At the time of this writing, this feature is not yet supported by the Selenium
developers.  However the author has altered the C# format in a limited
manner and it has worked well.</p>
</div>
</div>
<div class="section" id="executing-selenium-ide-tests-on-different-browsers">
<h2>Executing Selenium-IDE Tests on Different Browsers<a class="headerlink" href="#executing-selenium-ide-tests-on-different-browsers" title="Permalink to this headline">¶</a></h2>
<p>While Selenium-IDE can only run tests against Firefox, tests
developed with Selenium-IDE can be run against other browsers, using a
simple command-line interface that invokes the Selenium-RC server.  This topic
is covered in the <a class="reference internal" href="05_selenium_rc.jsp#html-suite"><span class="std std-ref">Run Selenese tests</span></a> section on Selenium-RC
chapter. The <em>-htmlSuite</em> command-line option is the particular feature of interest.</p>
</div>
<div class="section" id="troubleshooting">
<h2>Troubleshooting<a class="headerlink" href="#troubleshooting" title="Permalink to this headline">¶</a></h2>
<p>Below is a list of image/explanation pairs which describe frequent
sources of problems with Selenium-IDE:</p>
<p><em>Table view is not available with this format.</em></p>
<p>This message can be occasionally displayed in the Table tab when Selenium IDE is
launched. The workaround is to close and reopen Selenium IDE. See <a class="reference external" href="http://code.google.com/p/selenium/issues/detail?id=1008">issue 1008</a>.
for more information. If you are able to reproduce this reliably then please
provide details so that we can work on a fix.</p>
<hr class="docutils">
<p><em>error loading test case: no command found</em></p>
<p>You’ve used <strong>File=&gt;Open</strong> to try to open a test suite file. Use <strong>File=&gt;Open
Test Suite</strong> instead.</p>
<p>An enhancement request has been raised to improve this error message. See
<a class="reference external" href="http://code.google.com/p/selenium/issues/detail?id=1010">issue 1010</a>.</p>
<hr class="docutils">
<img alt="_images/chapt3_img28_Trouble_timing.png" src="_images/chapt3_img28_Trouble_timing.png">
<p>This type of <strong>error</strong> may indicate a timing problem, i.e., the element
specified by a locator in your command wasn’t fully loaded when the command
was executed.  Try putting a <strong>pause 5000</strong> before the command to determine
whether the problem is indeed related to timing.  If so, investigate using an
appropriate <strong>waitFor*</strong> or <strong>*AndWait</strong> command before the failing command.</p>
<hr class="docutils">
<img alt="_images/chapt3_img29_Trouble_param.png" src="_images/chapt3_img29_Trouble_param.png">
<p>Whenever your attempt to use variable substitution fails as is the
case for the <strong>open</strong> command above, it indicates
that you haven’t actually created the variable whose value you’re
trying to access.  This is
sometimes due to putting the variable in the <strong>Value</strong> field when it
should be in the <strong>Target</strong> field or vice versa.  In the example above,
the two parameters for the <strong>store</strong> command have been erroneously
placed in the reverse order of what is required.
For any Selenese command, the first required parameter must go
in the <strong>Target</strong> field, and the second required parameter (if one exists)
must go in the <strong>Value</strong> field.</p>
<hr class="docutils">
<p><em>error loading test case: [Exception… “Component returned failure code:
0x80520012 (NS_ERROR_FILE_NOT_FOUND) [nsIFileInputStream.init]” nresult:
“0x80520012 (NS_ERROR_FILE_NOT_FOUND)” location: “JS frame ::
chrome://selenium-ide/content/file-utils.js :: anonymous :: line 48” data: no]</em></p>
<p>One of the test cases in your test suite cannot be found.  Make sure that the
test case is indeed located where the test suite indicates it is located.  Also,
make sure that your actual test case files have the .html extension both in
their filenames, and in the test suite file where they are referenced.</p>
<p>An enhancement request has been raised to improve this error message. See
<a class="reference external" href="http://code.google.com/p/selenium/issues/detail?id=1011">issue 1011</a>.</p>
<hr class="docutils">
<img alt="_images/chapt3_img27_Trouble_extension.png" src="_images/chapt3_img27_Trouble_extension.png">
<p>Your extension file’s contents have not been read by Selenium-IDE.  Be
sure you have specified the proper pathname to the extensions file via
<strong>Options=&gt;Options=&gt;General</strong> in the <strong>Selenium Core extensions</strong> field.
Also, Selenium-IDE must be restarted after any change to either an
extensions file <em>or</em> to the contents of the <strong>Selenium Core extensions</strong>
field.</p>
</div>
</div>


          </div>

</body>
</html>